<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md15">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-card">
                                <div class="layui-card-header">查询教师-条件筛选</div>
                                <form class="layui-row layui-form " style="display: flex;flex-direction: row;margin-top: 10px" action="">

                                    <div class="layui-form-item layui-col-md8" >
                                        <label class="layui-form-label">教师</label>
                                        <div class="layui-input-block">
                                            <input name="deviceId" id="deviceId" class="layui-input" type="text" placeholder="请输入教师昵称或账号" autocomplete="off" lay-verify="deviceId">
                                        </div>
                                    </div>
                                    &nbsp;&nbsp;<a class="layui-btn" id="search"><i class="layui-icon layui-icon-search">&#xe615;</i></a>
                                </form>
                                <div class="layui-card-body">
                                    <table id="teachTable" lay-filter="teachTable"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/echarts.min.js"></script>
<script>
    var startInter = api.inter;
    var audio = "t", startTime, endTime;//初始化查询身份为教师,与当前的时间
    var arrTitle = [];//标题
    $(document).ready(function () {
        table();
        getDate();
    });

    //刷新
    function refresh() {
        table();
    }

    //获取当前的时间
    function getDate() {  //获取当前时间

        var myDate = new Date();

        var y = myDate.getFullYear();    //获取完整的年份

        var m = myDate.getMonth() + 1;       //获取当前月份(0-11,0代表1月)
        if (m < 10) {
            m = "0" + m;
        }

        var d = myDate.getDate();        //获取当前日(1-31)

        if (d < 10) {

            d = "0" + d;

        }
        var mytime = y + "-" + m + "-" + d;
        endTime = mytime;
        d = d - 9;
        startTime = y + "-" + m + "-" + d;

    }
    //教师查询
    $("#deviceId").bind('input propertychange', function () {
        $mess = $("#deviceId").val();
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#teachTable'
                , url: startInter //数据接口
                , title: '教师列表数据'
                , page: false //开启分页
                , toolbar: "#toolbarDemo"
                , method: 'post'
                , totalRow: true
                , limit: 20
                , limits: [20, 40, 60, 100]
                , where: {
                    action: "SearchUser",
                    keyword: $mess
                }
                , cols: [[//表头
                        {field: 'index', title: '序号', width: 60, fixed: 'left'}
                        , {field: 'uname', title: '账号', width: 120}
                        , {field: 'nick', title: '昵称', width: 120}
                        , {field: 'regtime', title: '注册时间', width: 170}
                        , {field: 'startCount', title: '登录次数', width: 90}
                        , {field: 'lastStartTime', title: '最近登录时间', width: 170}
                        , {field: 'classCount', title: '班级数', width: 80}
                        , {field: 'studentCount', title: '学生数', width: 80}
                        // , {field: 'isexp', title: '是否过期', width: 100, toolbar: "#isExp"}
                        // , {field: 'isout', title: '是否卡顿', width: 100, toolbar: "#isOut"}
                        // , {field: 'cs', title: '第几册', width: 100, toolbar: "#measure"}
                        // , {field: 'keyvalue', title: '激活码', width: 100}
                        , {field: 'countryName', title: '国家', width: 120}
                        , {field: 'zoneName', title: '区域', width: 180}
                        , {field: 'schoolName', title: '学校', width: 170}
                        , {field: '', toolbar: '#barDemo', title: '操作'}
                    ]]
                , done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        if (item.yid) {
                        } else {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css({"display": "block"});
                        }
                    });
                    if (res.count == 0) {
                        layer.msg("没有符合条件的数据哦");
                    }
                }
            });
            //监听工具操作事件
            table.on('tool(teachTable)', function (obj) {
                var data = obj.data, layEvent = obj.event;
                if (layEvent === 'delTeacher') {
                    layer.confirm('您确认要删除该信息吗？', {
                        btn: ['确认', '取消']
                    }, function () {
                        layer.confirm('请您再次确认删除操作，一旦删除将不可逆', {
                            btn: ['再次确认', '取消']
                        }, function () {
                            $.ajax({
                                type: "post",
                                cache: "false",
                                url: startInter,
                                data: {
                                    "action": "delUser",
                                    "userId": data.yid,

                                },
                                dataType: 'json',
                                success: function (res) {
                                    layer.msg(res.msg);
                                    if (res.code == 0) {
                                        obj.del(); //删除对应行（tr）的DOM结构
                                        layer.close(index);
                                    }
                                },
                                error: function (res) {
                                    console.log(res);
                                }
                            });
                            layer.msg("删除成功");
                        }, function () {
                            layer.msg("取消操作");
                        })
                    }, function () {
                        layer.msg("取消");
                    })
                }
            })
        });
    });

    function table() {
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#teachTable'
                , url: startInter //数据接口
                , method: 'post'
                , title: '教师列表数据'
                , page: true //开启分页
                , toolbar: "#toolbarDemo"
                , totalRow: true
                , limit: 20
                , limits: [20, 40, 60, 100]
                , where: {
                    action: "teacherStat",
                }
                , cols: [[//表头
                        {field: 'index', title: '序号', width: 60, fixed: 'left'}
                        , {field: 'uname', title: '账号', width: 120}
                        , {field: 'nick', title: '昵称', width: 120}
                        , {field: 'regtime', title: '注册时间', width: 170}
                        , {field: 'startCount', title: '登录次数', width: 90}
                        , {field: 'lastStartTime', title: '最近登录时间', width: 170}
                        , {field: 'classCount', title: '班级数', width: 80}
                        , {field: 'studentCount', title: '学生数', width: 80}
                        // , {field: 'isexp', title: '是否过期', width: 100, toolbar: "#isExp"}
                        // , {field: 'isout', title: '是否卡顿', width: 100, toolbar: "#isOut"}
                        // , {field: 'cs', title: '第几册', width: 100, toolbar: "#measure"}
                        // , {field: 'keyvalue', title: '激活码', width: 100}
                        , {field: 'countryName', title: '国家', width: 120}
                        , {field: 'zoneName', title: '区域', width: 180}
                        , {field: 'schoolName', title: '学校', width: 170}
                        , {field: '', toolbar: '#barDemo', title: '操作'}
                    ]]
                , done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        if (item.yid) {
                        } else {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css({"display": "block"});
                        }
                    });
                    if (res.count == 0) {
                        layer.msg("没有符合条件的数据哦");
                    }
                }
            });
            //监听工具操作事件
            table.on('tool(teachTable)', function (obj) {
                var data = obj.data, layEvent = obj.event;
                if (layEvent === 'delTeacher') {
                    layer.confirm('您确认要删除该信息吗？', {
                        btn: ['确认', '取消']
                    }, function () {
                        layer.confirm('请您再次确认删除操作，一旦删除将不可逆', {
                            btn: ['再次确认', '取消']
                        }, function () {
                            $.ajax({
                                type: "post",
                                cache: "false",
                                url: startInter,
                                data: {
                                    "action": "delUser",
                                    "userId": data.yid,
                                },
                                dataType: 'json',
                                success: function (res) {
                                    layer.msg(res.msg);
                                    if (res.code == 0) {
                                        obj.del(); //删除对应行（tr）的DOM结构
                                        layer.close(index);
                                    }
                                },
                                error: function (res) {
                                    console.log(res);
                                }
                            });
                            layer.msg("删除成功");
                        }, function () {
                            layer.msg("取消操作");
                        })
                    }, function () {
                        layer.msg("第一次取消");
                    })
                }
            })
        });
    }
</script>
<!--//注册时间-->
<script type="text/html" id="registerTime">
    {{#  if(d.acttime !=undefined){ }}
    <a style="color: #787878" class="layui-table-link">{{to_date(d.acttime)}}</a>
    {{#  } }}
</script>
<!--//到期时间-->
<script type="text/html" id="endTime">
    {{#  if(d.endtime !=undefined){ }}
    <a style="color: #787878" class="layui-table-link">{{to_date(d.endtime)}}</a>
    {{#  } }}
</script>
<!--//时间期限-->
<script type="text/html" id="expTime">
    {{#  if(d.exptime !=undefined){ }}
    <a style="color: #787878" class="layui-table-link">{{secondToDay(d.exptime)}}</a>
    {{#  } }}
</script>
<!--//是否激活-->
<script type="text/html" id="isState">
    {{#  if(d.isact =="1"){ }}
    <a style="color: green" class="layui-table-link">已激活</a>
    {{#  } }}
</script>
<!--//是否过期-->
<script type="text/html" id="isExp">
    {{#  if(d.isexp =="0"){ }}
    {{#  if(d.exptime <=259200000){ }}
    <a style="color: red" class="layui-table-link">即将过期</a>
    {{#  } }}
    <a style="color: green" class="layui-table-link">否</a>
    {{#  } }}
</script>
<!--//是否卡顿-->
<script type="text/html" id="isOut">
    {{#  if(d.isout =="0"){ }}
    <a style="color: green" class="layui-table-link">否</a>
    {{#  } }}
</script>
<!--//第几册-->
<script type="text/html" id="measure">
    {{#  if(d.cs !=undefined){ }}
    <a style="color: green" class="layui-table-link">第{{d.cs+1}}冊</a>
    {{#  } }}
</script>
<!--//最近启动时间-->
<script type="text/html" id="lastTime">
    <a class="layui-table-link">{{to_date(d.lastAccessTime)}}</a>
</script>
<!--//更新时间-->
<script type="text/html" id="updateTime">
    {{#  if(d.updatetime !=undefined){ }}
    <a class="layui-table-link">{{to_date(d.updatetime)}}</a>
    {{#  } }}
</script>
<!--操作-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="delTeacher">  <span class="icon iconfont">&#xe606;</span>删除</a>
</script>

<script id="toolbarDemo" type="text/html">

    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="refresh()"><i class="layui-icon">&#xe9aa;</i>
            刷新
        </button>
    </div>
</script>
